import { Indicator } from 'mint-ui'

let loadingCount = 0;

export default {
  show() {
    loadingCount++;
    if (loadingCount === 1) {
      Indicator.open({
        spinnerType: 'fading-circle'
      });
    }
  },

  close() {
    if (loadingCount >= 1) {
      loadingCount--;
    }

    if (loadingCount === 0) {
      // 异步处理，防止同步调用 show 和 close 问题
      setTimeout(() => {
        Indicator.close();
      }, 0);
    }
  }
}
